﻿using AutoMapper;
using B.S.Basic.Domain;
using B.S.Basic.ErrorCode;
using B.S.Basic.Infratrucate;
using MediatR;

namespace B.S.Basic.Write.API.Application
{
    public class AddMyCommandHandler : IRequestHandler<AddMyCommand, APIResult<object>>
    {
        private readonly IBaseRepositroy<MyExam> MyRepository;
        private readonly IMapper mapper;

        public AddMyCommandHandler(IBaseRepositroy<MyExam> MyRepository, IMapper mapper)
        {
            this.MyRepository = MyRepository;
            this.mapper=mapper;
        }
        public Task<APIResult<object>> Handle(AddMyCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            result.Code = EnumCode.添加成功;
            result.Message = EnumCode.添加成功.ToString();

            var entity = mapper.Map<MyExam>(request);
            MyRepository.Add(entity);


            return Task.FromResult(result);
        }
    }
}
